package com.galaxy.device.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.core.validate.AddGroup;
import com.galaxy.common.core.validate.EditGroup;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.device.domain.DeviceMaintenance;
import com.galaxy.device.domain.bo.DeviceMaintenanceBo;
import com.galaxy.device.domain.vo.DeviceMaintenanceVo;
import com.galaxy.device.service.IDeviceMaintenanceService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备维护Controller
 */
//@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/maintenance")
public class DeviceMaintenanceController {

    private final IDeviceMaintenanceService deviceMaintenanceService;

    /**
     * 查询设备维护列表
     */
    @GetMapping("/list")
    @SaCheckPermission("device:maintenance:list")
    public TableDataInfo<DeviceMaintenanceVo> list(DeviceMaintenanceBo bo, PageQuery pageQuery) {
        return deviceMaintenanceService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取设备维护详细信息
     */
    @GetMapping("/{id}")
//    @SaCheckPermission("device:maintenance:list")
    public R<DeviceMaintenanceVo> getInfo(@PathVariable Long id) {
        return R.ok(deviceMaintenanceService.getInfo(id));
    }

    /**
     * 新增设备维护
     */
    @Log(title = "设备维护", businessType = BusinessType.INSERT)
    @PostMapping
    @SaCheckPermission("device:maintenance:add")
    public R<DeviceMaintenance> add(@Validated(AddGroup.class) @RequestBody DeviceMaintenanceBo bo) {
        return R.ok(deviceMaintenanceService.add(bo));
    }

    /**
     * 修改设备维护
     */
    @Log(title = "设备维护", businessType = BusinessType.UPDATE)
    @PutMapping
//    @SaCheckPermission("device:maintenance:list")
    public R<DeviceMaintenance> update(@Validated(EditGroup.class) @RequestBody DeviceMaintenanceBo bo) {

        return R.ok(deviceMaintenanceService.update(bo));
    }

    /**
     * 删除设备维护
     */
    @Log(title = "设备维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @SaCheckPermission("device:maintenance:delete")
    public R<Void> delete(@PathVariable Long id) {
        deviceMaintenanceService.delete(id);
        return R.ok();
    }

    /**
     * 批量删除设备维护
     */
    @Log(title = "设备维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{ids}")
    @SaCheckPermission("device:maintenance:delete")
    public R<Void> deleteBatch(@PathVariable Long[] ids) {
        deviceMaintenanceService.deleteBatch(ids);
        return R.ok();
    }
}
